<template>
  <view>
        <!-- 1.请选择收获地址 -->
        <view class="address-choose-box" v-if="JSON.stringify(address) == '{}'">
           <button type="primary" size="mini" class="btnChoose" @click="chooseAddress">请选择收货地址+</button>
        </view>
        <!-- 2.收获地址信息 -->
        <view class="address-info-box" @click="chooseAddress" v-else>
          <view class="row1">
              <view class="row1-left">
                  <view class="username">收货人：<text>{{ address.userName }}</text> </view>
              </view>
              <view class="row1-right">
                 <view class="phone">电话: <text>{{ address.telNumber}}</text> </view>
                 <uni-icons type="arrowright" size="16"></uni-icons>
              </view>
          </view>
          <view class="row2">
              <view class="address">收货地址: <text>{{ addStr }}</text> </view>
          </view>
        </view>
        
        <!-- 3.底部边框 -->
        <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapState, mapMutations,mapGetters} from 'vuex';
  export default {
    name:"my-address",
    data() {
      return {
         // address:{}
      };
    },
    methods:{
     ...mapMutations('m_user', ['updateAddress']),
     async chooseAddress () {
          const [err, res] = await uni.chooseAddress().catch(err=>err);
          if (!err && res.errMsg=='chooseAddress:ok') {
              // this.address = res;
              this.updateAddress(res);
          }
      }
    },
    computed:{
        ...mapState('m_user',['address']),
        ...mapGetters('m_user',['addStr'])
    }
  }
</script>

<style lang="scss">
  // 1.选择收货地址
.address-choose-box {
   display: flex;
   justify-content: center;
   align-items: center;
   height: 90px;
}
// 2.地址详情
.address-info-box  {
    display: flex;
    flex-direction: column;
    justify-content:space-evenly;
    height: 90px;
    padding: 0 5px;
    font-size: 12px;
    color: #252525;
    .row1 {
      display: flex;
      justify-content: space-between;
      .row1-right{
         display: flex;
         uni-icons {
           margin-left: 5px;
         }
      }
    }
}

// 3.底部边框
.address-border  {
   height: 5px;
   width: 100%;
}
</style>